package com.gzhryc.shared_device.oem.code.member.dao.db;

import com.gzhryc.common.NumberTools;
import com.gzhryc.jdbc.annotaion.*;
import com.gzhryc.jdbc.enums.DateBranchTableType;
import com.gzhryc.shared_device.base.enums.EPayType;
import com.gzhryc.shared_device.oem.code.business.EBusinessType;
import com.gzhryc.shared_device.oem.code.device.EDeviceFunCode;
import com.gzhryc.shared_device.oem.code.member.dao.enums.MemberBusinessOrderEnum;
import com.gzhryc.shared_device.oem.code.profit.dao.enums.BusinessOrderEnum;

import java.io.Serializable;
import java.util.Date;

/**
 * 会员业务订单，可做会员的订单索引
 * @version 2022-09-29
 */
@DateBranchTable(type = DateBranchTableType.year)
@Table(name="member_business_order")
public class MemberBusinessOrder implements Serializable {

    private static final long serialVersionUID = 1L;

	@Id(auto = false)
    @Column(name = "trade_no", length = 32, notNull = true)
    protected String tradeNo;

    @Column(name = "title", notNull = true, note = "订单标题")
    protected String title;

    @Column(name = "member_id", notNull = true, note = "会员ID")
    protected Long memberId;

    @Column(name = "member_name", note = "会员名称")
    protected String memberName;
    
    @Column(name = "member_phone", length = 16, note = "会员手机号")
    protected String memberPhone;

    @Column(name = "agent_id", note = "代理ID")
    protected Long agentId;

    //设备相关

    @Column(name = "device_type_name",note = "设备类型名称")
    protected String deviceTypeName;

    @Column(name = "device_sn", notNull = true, note = "设备序列号")
    protected String deviceSn;

    @Column(name = "slot_num", note = "设备卡槽")
    protected Integer slotNum;

    @Column(name = "bind_note", note = "设备绑定信息")
    protected String bindNote;

    @Column(name = "device_fun_code", notNull = true, note = "设备功能Code")
    protected String deviceFunCode;

    @Column(name = "business_type", notNull = true, note = "业务类型")
    protected String businessType;

    @Column(name = "cost_mode", notNull = true, note = "收费模式")
    protected Integer costMode;

    @Column(name = "cost_mode_name", note = "收费模式名称")
    protected String costModeName;

    //网点相关

    @Column(name = "place_id", notNull = true, note = "网点ID")
    protected Long placeId;

    @Column(name = "place_name", note = "网点名称")
    protected String placeName;

    @Column(note = "省")
    protected String province;

    @Column(note = "市")
    protected String city;

    @Column(name = "city_area", note = "城区")
    protected String cityArea;

    @Column(name = "area_code", length = 128, note = "地区ID，以逗号分隔")
    protected String areaCode;

    //支付相关

    @Column(name = "pay_type", notNull = true, note = "支付方式")
    protected Integer payType;

    @Column(name = "money", notNull = true, defVal = "0", note = "订单金额，单位：厘")
    protected Long money;

    @Column(name = "pay_money", notNull = true, defVal = "0", note = "支付金额，单位：分")
    protected Integer payMoney;

    @Column(name = "wallet_money", notNull = true, defVal = "0", note = "钱包金额，单位：厘")
    protected Long walletMoney;

    @Column(name = "discount_money", notNull = true, defVal = "0", note = "优惠金额，单位：厘")
    protected Long discountMoney;

    @Column(name = "coupon_id", note = "优惠券ID")
    protected String couponId;

    @Column(name = "coupon_title", length = 255, note = "优惠标题")
    protected String couponTitle;

    @Column(notNull = true, defVal = "1", note = "订单状态")
    protected Integer state;

    @Column(name="vv_state",notNull = true, defVal = "0",note = "核销券状态，首位状态，1:未领取，2:已领取，后面为核销券类型")
    protected Integer verificationVoucherState;

    @Column(name = "update_date", autoUpdateTime = true, note = "修改时间")
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    @DateBranchJoin
    @JoinField(name = "divide_state",fromField = "trade_no",toTable = "business_order",toField = "trade_no",type = "LEFT")
    protected Integer divideState;

    public String getTradeNo() {
        return tradeNo;
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDeviceTypeName() {
        return deviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        this.deviceTypeName = deviceTypeName;
    }

    public String getDeviceSn() {
        return deviceSn;
    }

    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }

    public String getBindNote() {
        return bindNote;
    }

    public void setBindNote(String bindNote) {
        this.bindNote = bindNote;
    }

    public Long getPlaceId() {
        return placeId;
    }

    public void setPlaceId(Long placeId) {
        this.placeId = placeId;
    }

    public String getPlaceName() {
        return placeName;
    }

    public void setPlaceName(String placeName) {
        this.placeName = placeName;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCityArea() {
        return cityArea;
    }

    public void setCityArea(String cityArea) {
        this.cityArea = cityArea;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public Long getAgentId() {
        return agentId;
    }

    public void setAgentId(Long agentId) {
        this.agentId = agentId;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public Integer getSlotNum() {
        return slotNum;
    }

    public void setSlotNum(Integer slotNum) {
        this.slotNum = slotNum;
    }

    public Integer getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(Integer payMoney) {
        this.payMoney = payMoney;
    }

    public Long getDiscountMoney() {
        return discountMoney;
    }

    public void setDiscountMoney(Long discountMoney) {
        this.discountMoney = discountMoney;
    }

    public Long getWalletMoney() {
        return walletMoney;
    }

    public void setWalletMoney(Long walletMoney) {
        this.walletMoney = walletMoney;
    }

    public String getCouponId() {
        return couponId;
    }

    public void setCouponId(String couponId) {
        this.couponId = couponId;
    }

    public String getCouponTitle() {
        return couponTitle;
    }

    public void setCouponTitle(String couponTitle) {
        this.couponTitle = couponTitle;
    }

    public String getDeviceFunCode() {
        return deviceFunCode;
    }

    public void setDeviceFunCode(String deviceFunCode) {
        this.deviceFunCode = deviceFunCode;
    }

    public String getBusinessType() {
        return businessType;
    }

    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public String getMemberPhone() {
        return memberPhone;
    }

    public void setMemberPhone(String memberPhone) {
        this.memberPhone = memberPhone;
    }

    public Integer getCostMode() {
        return costMode;
    }

    public void setCostMode(Integer costMode) {
        this.costMode = costMode;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getVerificationVoucherState() {
        return verificationVoucherState;
    }

    public void setVerificationVoucherState(Integer verificationVoucherState) {
        this.verificationVoucherState = verificationVoucherState;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getCostModeName() {
        return costModeName;
    }

    public void setCostModeName(String costModeName) {
        this.costModeName = costModeName;
    }

    public String getMoneyStr() {
        return NumberTools.getMoneyLiStr(this.money);
    }

    public String getDiscountMoneyStr() {
        return NumberTools.getMoneyLiStr(this.discountMoney);
    }

    public String getPayMoneyStr() {
        return NumberTools.getMoneyStr(this.payMoney);
    }

    public String getWalletMoneyStr() {
        return NumberTools.getMoneyLiStr(this.walletMoney);
    }

    public String getPayTypeName() {
        return EPayType.note(this.payType);
    }

    public String getAreaName() {
        return this.province + "-" + this.city + "-" + this.cityArea;
    }

    public String getStateName() {
        return MemberBusinessOrderEnum.State.note(this.state);
    }

    public String getDeviceFunCodeName() {
        return EDeviceFunCode.note(this.deviceFunCode);
    }

    public String getBusinessTypeName(){
        return EBusinessType.note(this.businessType);
    }

    public String getPayInfo() {
        String temp = "";
        if (this.payMoney > 0) {
            if (EPayType.WXPay.index().equals(this.payType)) {
                temp = temp + ",微信支付：" + this.getPayMoneyStr() + "元";
            } else if (EPayType.Alipay.index().equals(this.payType)) {
                temp = temp + ",支付宝支付：" + this.getPayMoneyStr() + "元";
            } else {
                temp = temp + ",第三方支付：" + this.getPayMoneyStr() + "元";
            }
        }
        if (this.walletMoney > 0) {
            temp = temp + ",钱包支付：" + this.getWalletMoneyStr() + "元";
        }
        if (temp.length() > 0) {
            temp = temp.substring(1);
        } else {
            temp = "暂无支付";
        }
        return temp;
    }

    public void setDivideState(Integer divideState) {
        this.divideState = divideState;
    }

    public Integer getDivideState() {
        return divideState;
    }

    public String getDivideStateName(){
        if(this.divideState != null) {
            return BusinessOrderEnum.DivideState.note(this.divideState);
        }else{
            return BusinessOrderEnum.DivideState.Wait.note();
        }
    }

    public String getVerificationVoucherStateName(){
        return MemberBusinessOrderEnum.State.note(this.verificationVoucherState);
    }
}
